# -*- coding: utf-8 -*-

from xml.dom import minidom
import urllib2
import re
import tweepy
from passwd import forecasthoge as p

consumer_key        = p.consumer_key
consumer_secret     = p.consumer_secret
access_token        = p.access_token
access_token_secret = p.access_token_secret

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth_handler=auth)

xdoc = minidom.parse( urllib2.urlopen( 'http://weather.livedoor.com/forecast/webservice/rest/v1?city=63&day=today' ) )

telop = xdoc.getElementsByTagName( 'telop' )[ 0 ].firstChild.data
date  = xdoc.getElementsByTagName( 'forecastdate' )[ 0 ].firstChild.data
description = re.sub( '\.\.\..*$', '...', xdoc.getElementsByTagName( 'description' )[ 0 ].firstChild.data )

result = telop + ' ' + date + ' ' + description

api.update_status(result)
